package com.tange.feature.development.toolkit;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;

import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;

import com.tange.core.backend.service.interceptor.HttpLoggingInterceptor;

public class HttpInterceptNotification {

    private static final int NOTIFICATION_ID = 7651;


    public static void showNotification(Activity activity){

        if (!HttpLoggingInterceptor.enableCache) {
            return;
        }

        Intent intent = new Intent(activity, HttpInterceptListActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent;
        if (android.os.Build.VERSION.SDK_INT >= 23) {
            pendingIntent = PendingIntent.getActivity(activity, 0, intent, PendingIntent.FLAG_IMMUTABLE);
        }else {
            pendingIntent = PendingIntent.getActivity(activity, 0, intent, 0);
        }

        String notificationId = "1";
        NotificationCompat.Builder builder = new NotificationCompat.Builder(activity, notificationId)
                .setContentTitle("网络请求记录中...")
                .setContentText("点击查看所有网络请求")
                .setSmallIcon(R.drawable.debug_ic_launcher)
                .setOngoing(true)
                .setLargeIcon(BitmapFactory.decodeResource(activity.getResources(),R.drawable.debug_ic_launcher))
                .setPriority(NotificationCompat.PRIORITY_MIN)
                .setContentIntent(pendingIntent)
                .setAutoCancel(false);
        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(activity);

        notificationManager.cancel(NOTIFICATION_ID);
        notificationManager.notify(NOTIFICATION_ID, builder.build());
    }

}
